﻿using System;
using System.Collections.Generic;
using XL.Framework.Domain.Core;

namespace Guitar.Comet.Message
{
    /// <summary>
    /// 信封
    /// </summary>
    public class MessageEnvelope : AggregateRoot
    {
        public MessageEnvelope(string toClientName, string name, IDictionary<object, object> body, DateTime? expire = null)
        {
            this.Name = name;
            if (body == null) body = new Dictionary<object, object>();

            this.Body = body;
            this.ToClientName = toClientName;
            if (expire.HasValue) this.Expire = expire.Value;
            else this.Expire = DateTime.Now.AddMinutes(10);

        }

        /// <summary>
        /// 消息ID
        /// </summary>
        public Guid ID { get; set; }

        /// <summary>
        /// 消息名称
        /// </summary>
        public string Name { get; private set; }

        /// <summary>
        /// 消息主题
        /// </summary>
        public IDictionary<object, object> Body { get; private set; }

        /// <summary>
        /// 消息发生时间
        /// </summary>
        public DateTime CreatedTime { get; set; }

        /// <summary>
        /// 0==成功发送的消息,1==失败发送的消息
        /// </summary>
        public int Status { get; set; }

        public string ToClientName { get; private set; }

        /// <summary>
        /// 过期时间
        /// </summary>
        public DateTime Expire { get; private set; }
    }
}
